﻿using System;
using System.Web;

using OctoOS;
using OctoOS.UI;


public partial class __deleteArticle : OOSPage
{
	class PathInfo
	{
		[PathInfoMember(0)]
		[RangeValidator(1, Int64.MaxValue)]
		[IntegerBase(64)]
		internal long ID = 0;
	}

	PathInfo _pathInfo;

	protected void Page_Init(object sender, EventArgs e)
	{
		_pathInfo = EnablePathInfo<PathInfo>();
	}

    protected void Page_Load(object sender, EventArgs e)
    {
		var article = ApiService.GetArticle(OOSRequest.Current, _pathInfo.ID);
		if(!OOSRequest.Current.IsModerator &&
				article.UserID != OOSRequest.Current.UserID)
		{
			throw new HttpException();
		}

		PageTitle = Resources.Main.deleteArticle_Title;
		deleteMsg.SetContent(String.Format(Resources.Main.deleteArticle_Question, article.Title));
		deleteMsg.AddSubmit(Resources.Main.shared_Yes, yesBtn_Click);
		deleteMsg.AddCancel(Resources.Main.shared_No, Urls.GetEditArticle(_pathInfo.ID));
    }

	protected void yesBtn_Click(object sender, EventArgs e)
	{
		ApiService.DeleteArticle(OOSRequest.Current, _pathInfo.ID);
		Response.Redirect(Urls.GetMyArticles());
	}
}